-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve compiler errors that appear due to useDefineForClassFields #241544
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree company="Google" |
@jrieken, would you be willing to take a look at this? |
@trevorade Thanks for reaching out and starting this. This is a large PR and something we need to coordinate across the team. Usually, we have reservations against PRs that touch very many code owner areas but this seems mostly mechanical and exception-worthy. I will circle this with the team and see how folks respond. Generally, I am positive about this change and it seems this must happen anyways sooner or later.
Do you have a feel for what that would be? @mjbvz You initial concern in #186726 (comment) seems to have fixed, right? Any other insights this that you have? |
Thx. This is exactly what I expected. That seeing such a large PR from a new contributor would raise some eyebrows and require some discussion. Once you guys are fully comfortable with this PR, I will re-sync, again fix all new errors, and move forward with submit. It would really be best if the codebase had some method to prevent backsliding but I'm unaware of any short of enabling
When you actually enable the flag, the code emitted changes quite a bit more. You start using true class fields rather than object properties throughout. While testing with this flag enabled, I wasn't able to actually run VSCode due to some errors. I forget exactly what. Easiest way to test that out would be to patch this PR and turn on the flag to experiment. Anyways, my point is that I would expect that someone would want to do rigorous testing once enabling this flag. This PR is safer as it only fixes all the compiler errors without actually making the change.
Matt was correct that there were additional runtime errors to consider. In the case of moving only the initializers that reference parameter properties, there's still the issue of other non-constructor initializers that access other fields initialized in the constructor from a function. This can be safe if the function is evaluated after the constructor or unsafe if evaluated immediately (i.e. via I can only be as confident as your tests though. I would hope that someone in the VSCode team could patch this PR and test things out a bit to check for anything that may not be as well covered in tests. Beyond what I fixed, it's possible there are other code execution order changes that will be introduced via enabling |
We can prevent erosion by adding another tsconfig which enables useDefineForClassFields and do a separate check with that. Will slow down CI by a tiny bit, for the time being, but something that we have done successfully in the past |
These changes go a ways towards addressing #186726
These changes DO NOT include setting
useDefineForClassFields
totrue
so backsliding is still possible.These changes were done by hand over a period of about five focused hours. There were 500 errors when I started.
The process I used was:
useDefineForClassFields
in the base tsconfig file (NOT IN THIS PR)npm run watch
waitForState
andrecomputeInitiallyAndOnChange
and inline any impactedderived
fieldsTo truly enable
useDefineForClassFields
, more changes will more than likely need to be made. For now, I was interested in tackling the compilation errors.All tests pass with these changes.
If the VSCode team would like to take over this PR, that's fine.
The motivation for making these changes is that, at Google, we build this codebase internally. We are going to enable the compilation errors related to
useDefineForClassFields
in our internal typescript compiler settings (without actually turning on those transpilation changes, similar to microsoft/TypeScript#59623). So we would much prefer to fix these issues in your codebase rather than maintain a huge 200 file patch :P